package com.ftg.learn.util.desensitization;

import org.springframework.stereotype.Component;

/**
 * 中文脱敏化处理
 * @author kangjx
 * @date 2022/11/9
 */
public class ChineseNameDesensitization extends AbstractDesensitization {

    /**
     * 长度化处理
     */
    final int valLen = 3;

    @Override
    public String serialize(String value) {
        String serializeValue = "";
        if(value.length() < valLen){
            serializeValue = value.replaceAll(".*(?=[\\u4e00-\\u9fa5])","*");
        }else{
            serializeValue = value.replaceAll("(?<=[\\u4e00-\\u9fa5]).*(?=[\\u4e00-\\u9fa5])","*");
        }
        return serializeValue;
    }

}
